package com.ruoyi.app.controller;

import com.ruoyi.app.domain.AppArticleMine;
import com.ruoyi.app.service.AppArticleMineService;
import com.ruoyi.cms.domain.Comment;
import com.ruoyi.cms.service.ICommentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/appArticleMine/")
public class AppArticleMineController extends BaseController {
    @Autowired
    private AppArticleMineService appArticleMineService;

    @Autowired
    private ICommentService commentService;

    @ResponseBody
    @RequestMapping("add")
    public AjaxResult insertArticleMine(AppArticleMine articleMine) {
        long userId = ShiroUtils.getSysUser().getUserId();
        articleMine.setUserId(userId);
        return AjaxResult.success(appArticleMineService.insertArticleMine(articleMine));
    }

    @ResponseBody
    @RequestMapping("del")
    public AjaxResult delArticleMine(long id) {
        return AjaxResult.success(appArticleMineService.delArticleMine(id));
    }

    @ResponseBody
    @RequestMapping("upArticleMine")
    public AjaxResult upArticleMine(long id) {
        return AjaxResult.success(appArticleMineService.upArticleMine(id));
    }

    @ResponseBody
    @RequestMapping("queryArticleMine")
    public AjaxResult queryArticleMine(AppArticleMine appArticleMine) {
        long userId = ShiroUtils.getSysUser().getUserId();
        appArticleMine.setUserId(userId);
        AppArticleMine aMin = appArticleMineService.queryArticleMine(appArticleMine);
        return AjaxResult.success(aMin);
    }

    @PostMapping("addComment")
    @ResponseBody
    public AjaxResult addComment(Comment comment) {
        String userId = ShiroUtils.getSysUser().getUserId().toString();
        comment.setUserId(userId);
        comment.setUserName( ShiroUtils.getSysUser().getUserName());
        return toAjax(commentService.insertComment(comment));
    }

}
